package com.woniu.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.woniu.commons.exception.YogaException;
import com.woniu.dao.mapper.YLeagueClassOrderPeopleMapper;
import com.woniu.model.form.AddLeagueClassOrderPeopleForm;
import com.woniu.model.model.YLeagueClassOrderPeople;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.woniu.service.YLeagueClassOrderPeopleService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author 吴彦祖
 * @since 2024年05月23日
 */
@Service
public class YLeagueClassOrderPeopleServiceImpl extends ServiceImpl<YLeagueClassOrderPeopleMapper, YLeagueClassOrderPeople> implements YLeagueClassOrderPeopleService {

    /**
     * 新增团课的学员
     * @param form
     * @return
     */
    @Override
    public Integer addLeagueClassOrderPeople(AddLeagueClassOrderPeopleForm form) {
        List<YLeagueClassOrderPeople> list = baseMapper.selectList(new QueryWrapper<YLeagueClassOrderPeople>().eq("league_class_id", form.getLeagueClassId()).eq("user_id", form.getUserId()));
        if (list.size()!=0){
            throw new YogaException(3106,"已存在该关系");
        }
        YLeagueClassOrderPeople leagueClassOrderPeople = BeanUtil.toBean(form, YLeagueClassOrderPeople.class);
        int insert = baseMapper.insert(leagueClassOrderPeople);
        return insert;
    }
}
